package com.Leetcode;

import java.util.HashMap;
import java.util.Map;

public class Index219 {
	public static void main(String[] args) {
		int[] nums = new int[] {1,2,3,1,2,3};
		boolean flag = containsNearbyDuplicate(nums, 2);
		System.out.println(flag);	
	}
	
	public static boolean containsNearbyDuplicate(int[] nums, int k) {
		Map<Integer,Integer> map = new HashMap();
		for (int i = 0; i < nums.length; i++) {
			if(map.containsKey(nums[i]))
				if(i - map.get(nums[i]) <= k) return true;
			map.put(nums[i], i);
		}
		return false;
    }
}
